package com.hanhai.zrb.api.util;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Random;


public class NumberUtil {
	
	public static String getPercent(int x, int y) {
		  double percentX = x * 1.0;
		  double percentY = y * 1.0;
		  double percent = percentX / percentY;
		  DecimalFormat df = new DecimalFormat("##.00%");
		  return df.format(percent);
	}
	
	public static String getPercent(float x, float y) {
		  double percentX = x * 1.0;
		  double percentY = y * 1.0;
		  double percent = percentX / percentY;
		  DecimalFormat df = new DecimalFormat("##.00%");
		  return df.format(percent);
	}
	
	public static double getPercentNumber(float x, float y) {
		  double percentX = x * 1.0;
		  double percentY = y * 1.0;
		  return percentX / percentY;
	}
	
	public static float roundFloat(float v) {// 截取2位  
        BigDecimal b = new BigDecimal(Float.toString(v));  
        BigDecimal one = new BigDecimal("1");  
        return b.divide(one, 2, BigDecimal.ROUND_DOWN).floatValue();  
    }  
	
	public static int getRandomNumber(int min, int max) {
		return new Random().nextInt(max - min) + min; 
	}
	
	public static void main(String[] args){
		System.out.println("float value is:"+roundFloat(2.1f));
		System.out.println("float value is:"+roundFloat(2f));
		System.out.println("float value is:"+roundFloat(2.0001f));
		System.out.println("float value is:"+roundFloat(2.54678f));
	}
}
